package com.weavernorth.create;


import com.weaver.general.BaseBean;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.logging.Log;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.workflow.webservices.*;


public class DetailEducation {


    private static Log log = org.apache.commons.logging.LogFactory.getLog(DetailEducation.class.getName());

    public WorkflowRequestTableRecord[] detailEducation(JSONArray educationJsonArr) {
        BaseBean bb = new BaseBean();
        //获取简历的基础信息
        WorkflowRequestTableRecord[] wrtri = new WorkflowRequestTableRecord[educationJsonArr.size()];
        log.info("教育经历：" + educationJsonArr.size());
        if (educationJsonArr != null) {
            WorkflowRequestTableField[] wrti;
            log.info("educationJson.size()的长度" + educationJsonArr.size());
            //同一明细表可能存在多个，所以循环处理
            for (int i = 0; i < educationJsonArr.size(); i++) {
                JSONObject jsonObject = JSONObject.fromObject(educationJsonArr.get(i));
                //添加入学日期字段
                //从JSONobject中获取字段信息
                String strRxrq = String.valueOf(jsonObject.get("startDate"));
                log.info("入学日期：" + strRxrq);
                //数组有六个字段长度为6
                wrti = new WorkflowRequestTableField[7];
                wrti[0] = new WorkflowRequestTableField();
                //字段在数据库中的字段名
                wrti[0].setFieldName("rxrq");
                //赋值
                wrti[0].setFieldValue(strRxrq);
                wrti[0].setView(true);
                wrti[0].setEdit(true);

                //添加毕业日期字段
                //从JSONobject中获取字段信息
                String strByrq = String.valueOf(jsonObject.get("endDate"));
                log.info("毕业日期：" + strByrq);
                wrti[1] = new WorkflowRequestTableField();
                //字段在数据库中的字段名
                wrti[1].setFieldName("byrq");
                //赋值
                wrti[1].setFieldValue(strByrq);
                wrti[1].setView(true);
                wrti[1].setEdit(true);

                //添加学历字段
                //从JSONobject中获取字段信息
                String strXl = String.valueOf(jsonObject.get("diploma"));
                log.info("学历：" + strXl);
                wrti[2] = new WorkflowRequestTableField();
                //字段在数据库中的字段名
                wrti[2].setFieldName("xl");
                //赋值
                //查询编码表对应的值
                String xlSql = "select xl from uf_xl where xlbmdy = '" + strXl + "'";
                RecordSet rsxl = new RecordSet();
                rsxl.execute(xlSql);
                if (rsxl.next()) {
                    wrti[2].setFieldValue(rsxl.getString("xl"));
                } else {
                    wrti[2].setFieldValue(strXl);
                }
                wrti[2].setView(true);
                wrti[2].setEdit(true);

                //添加院校培训机构字段
                //从JSONobject中获取字段信息
                String strYxpxjg = String.valueOf(jsonObject.get("schoolName"));
                log.info("院校培训机构：" + strYxpxjg);
                wrti[3] = new WorkflowRequestTableField();
                //字段在数据库中的字段名
                wrti[3].setFieldName("yxpxjg");
                //赋值
                wrti[3].setFieldValue(strYxpxjg);
                wrti[3].setView(true);
                wrti[3].setEdit(true);

                //添加所学专业字段
                //从JSONobject中获取字段信息
                String strSxzy = String.valueOf(jsonObject.get("major"));
                log.info("所学专业：" + strSxzy);
                //查询所学专业
                rsxl.executeQuery("select sxzy from uf_sxzy where sxzybm=?",strSxzy);
                rsxl.next();
                String strSxzyDy= Util.null2String(rsxl.getString("sxzy"));
                log.info(strSxzyDy+";所学专业：" + strSxzy);
                wrti[4] = new WorkflowRequestTableField();
                //字段在数据库中的字段名
                wrti[4].setFieldName("sxzy");
                //赋值
                wrti[4].setFieldValue(strSxzyDy);
                wrti[4].setView(true);
                wrti[4].setEdit(true);

                //添加学位字段
                //从JSONobject中获取字段信息
                String strXw = String.valueOf(jsonObject.get("degree"));
                log.info("学位：" + strXw);
                wrti[5] = new WorkflowRequestTableField();
                //字段在数据库中的字段名
                wrti[5].setFieldName("xw");
                if (("0/435/479").equals(strXw)) {
                    String bachelor = bb.getPropValue("porturl", "bachelor");
                    wrti[5].setFieldValue(bachelor);
                }
                if (("0/435/486").equals(strXw)) {
                    String master = bb.getPropValue("porturl", "master");
                    wrti[5].setFieldValue(master);
                }
                if (("0/435/487").equals(strXw)) {
                    String doctor = bb.getPropValue("porturl", "doctor");
                    wrti[5].setFieldValue(doctor);
                }
                if (("0/435/477").equals(strXw)) {
                    String degree = bb.getPropValue("porturl", "degree");
                    wrti[5].setFieldValue(degree);
                }
                //赋值
                wrti[5].setFieldValue(strXw);
                wrti[5].setView(true);
                wrti[5].setEdit(true);

                //添加学制字段
                //从JSONobject中获取字段信息
                String strXz = String.valueOf(jsonObject.get("SchoolSystem"));
                log.info("学制：" + strXz);
                wrti[6] = new WorkflowRequestTableField();
                //字段在数据库中的字段名
                wrti[6].setFieldName("xz");
                //赋值
                wrti[6].setFieldValue(strXz);
                wrti[6].setView(true);
                wrti[6].setEdit(true);

                wrtri[i] = new WorkflowRequestTableRecord();
                wrtri[i].setWorkflowRequestTableFields(wrti);
            }
            }
        return wrtri;
    }
}




